﻿using System.IO;
using System.Collections.Generic;

namespace Common
{
    /// <summary>
    /// Read text from file
    /// </summary>
    public static class ReadCustomText
    {
        //private static HybridDictionary textDict = new HybridDictionary();
        private static readonly Dictionary<string, string> textDict = new Dictionary<string, string>();
        

        static ReadCustomText()
        {
            string m_settingsPath;
            string alldata = string.Empty;
            m_settingsPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            m_settingsPath += @"\CustomText.txt";
            if (!File.Exists(m_settingsPath))
                throw new FileNotFoundException(m_settingsPath + " could not be found.");
            else
            {
                alldata = File.OpenText(m_settingsPath).ReadToEnd().Replace("\n", "").Replace("\r", "").Replace("\"", "").Replace("\t","").Replace("key=", "▄").Replace("value=", "▄");// alt 220 ▄
            }
            string[] splitData = alldata.Split('▄');
            for (int i = 0; i < splitData.Length; )
            {
                if (string.IsNullOrEmpty(splitData[i].Trim()))
                {
                    i++;
                    continue;
                }
                textDict.Add(splitData[i].Trim(), splitData[++i]);
                i++;
            }
        }

        public static string GetString(string Key)
        {
            string val = textDict[Key].ToString().Trim();
            return string.IsNullOrEmpty(val) ? "!ERROR!" : val;
        }

    }
}

